package com.pwt.controller.largescreen;

import com.pwt.common.CustomException;
import com.pwt.common.ResultPage;
import com.pwt.entity.Images;
import com.pwt.service.ImagesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;

/**
 * @author dw
 * @date 2021/12/20 20:45
 * @Description
 */
@RestController
@Tag(name = "图片展示",description = "图片展示")
public class ImagesShowController {

    private ImagesService imagesService;

    public ImagesShowController(ImagesService imagesService) {
        this.imagesService = imagesService;
    }

    @Operation(description = "图片展示页面",summary = "图片展示页面")
    @GetMapping("/show_images")
    @Parameters({
            @Parameter(name = "name",description = "查询名称",required = false),
            @Parameter(name = "startTime",description = "开始时间",required = false),
            @Parameter(name = "endTime",description = "结束时间",required = false),
            @Parameter(name = "page",description = "当前页",required = true),
            @Parameter(name = "limit",description = "每页展示数",required = true),
    })
    public ResultPage<Images> showImages(@RequestParam(required = false) String name, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, Integer page, Integer limit, HttpServletRequest request) {
        return this.imagesService.imagesPage(name,startTime,endTime,page,limit,"http://"+request.getServerName()+":"+request.getServerPort());
    }

    @Operation(description = "图片下载",summary = "图片下载")
    @GetMapping("/downLoadImages")
    public void downLoadImages(String id, HttpServletResponse response) throws CustomException, IOException {
        this.imagesService.downLoadImages(id,response);
    }

}
